package com.haixiaoke.saas.order.service.impl;

import java.util.List;

import cn.hutool.core.collection.CollectionUtil;
import com.haixiaoke.saas.common.constant.OrderConstants;
import com.haixiaoke.saas.common.utils.DateUtils;
import com.haixiaoke.saas.common.weChat.domain.ParseParam;
import com.haixiaoke.saas.order.domain.CheckOutOrder;
import com.haixiaoke.saas.order.domain.OrderLessee;
import com.haixiaoke.saas.order.mapper.CheckOutOrderMapper;
import com.haixiaoke.saas.order.service.ICheckOutOrderService;
import com.haixiaoke.saas.order.service.IOrderLesseeService;
import com.haixiaoke.saas.order.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 退房订单Service业务层处理
 * 
 * @author panda
 * @date 2024-04-19
 */
@Service
public class CheckOutOrderServiceImpl implements ICheckOutOrderService {
    @Autowired
    private CheckOutOrderMapper checkOutOrderMapper;
    @Autowired
    private IOrderService orderService;
    @Autowired
    private IOrderLesseeService orderLesseeService;

    /**
     * 查询退房订单
     * 
     * @param checkOutOrderId 退房订单主键
     * @return 退房订单
     */
    @Override
    public CheckOutOrder selectCheckOutOrderByCheckOutOrderId(String checkOutOrderId) {
        return checkOutOrderMapper.selectCheckOutOrderByCheckOutOrderId(checkOutOrderId);
    }

    /**
     * 查询退房订单列表
     * 
     * @param checkOutOrder 退房订单
     * @return 退房订单
     */
    @Override
    public List<CheckOutOrder> selectCheckOutOrderList(CheckOutOrder checkOutOrder) {
        return checkOutOrderMapper.selectCheckOutOrderList(checkOutOrder);
    }

    /**
     * 新增退房订单
     * 
     * @param checkOutOrder 退房订单
     * @return 结果
     */
    @Override
    public int insertCheckOutOrder(CheckOutOrder checkOutOrder) {
        return checkOutOrderMapper.insertCheckOutOrder(checkOutOrder);
    }

    /**
     * 修改退房订单
     * 
     * @param checkOutOrder 退房订单
     * @return 结果
     */
    @Override
    public int updateCheckOutOrder(CheckOutOrder checkOutOrder) {
        return checkOutOrderMapper.updateCheckOutOrder(checkOutOrder);
    }

    /**
     * 批量删除退房订单
     * 
     * @param checkOutOrderIds 需要删除的退房订单主键
     * @return 结果
     */
    @Override
    public int deleteCheckOutOrderByCheckOutOrderIds(String[] checkOutOrderIds) {
        return checkOutOrderMapper.deleteCheckOutOrderByCheckOutOrderIds(checkOutOrderIds);
    }

    /**
     * 删除退房订单信息
     * 
     * @param checkOutOrderId 退房订单主键
     * @return 结果
     */
    @Override
    public int deleteCheckOutOrderByCheckOutOrderId(String checkOutOrderId) {
        return checkOutOrderMapper.deleteCheckOutOrderByCheckOutOrderId(checkOutOrderId);
    }

    @Override
    public CheckOutOrder selectCheckOutOrderByOrderId(String orderId) {
        return checkOutOrderMapper.selectCheckOutOrderByOrderId(orderId);
    }

    @Override
    public void supplementaryPayCallbackOrder(ParseParam parseParam) {
        // TODO: 2024/4/26 修改相关数据
        CheckOutOrder checkOutOrder = checkOutOrderMapper.selectCheckOutOrderByCheckOutOrderId(parseParam.getOutTradeNo());
        checkOutOrder.setRefundOrderState(OrderConstants.ORDER_STATE_SUPPLEMENTARY_PAYMENT);
        checkOutOrder.setPayTime(DateUtils.getNowDate());
        checkOutOrderMapper.updateCheckOutOrder(checkOutOrder);
    }

    @Override
    public int countOrderState(Long userId) {
        return checkOutOrderMapper.countOrderState(userId);
    }

    @Override
    public List<CheckOutOrder> selectCheckOutOrderByOrderIds(List<String> orderIds) {
        if (CollectionUtil.isEmpty(orderIds)) {
            return null;
        }
        return checkOutOrderMapper.selectCheckOutOrderByOrderIds(orderIds);
    }
}
